package com.workspace.js_website.controller;

import com.workspace.js_website.bean.RespBean;
import com.workspace.js_website.bean.MetaBean;
import com.workspace.js_website.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 页面搜索相关控制
 */

@CrossOrigin
@RestController
@RequestMapping("/search")
public class SearchController {

    private final SearchService searchService;

    @Autowired
    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }

    @GetMapping("/getResource")
    public RespBean getResource(@RequestParam String word){
        MetaBean meta = new MetaBean(200,"获取成功");
        return new RespBean (searchService.getResource(word), meta);
    }

    @GetMapping("/getKeyword")
    public RespBean getKeyword(@RequestParam String word){
        MetaBean meta = new MetaBean(200,"获取成功");
        return new RespBean (searchService.getKeyword(word), meta);
    }

    @GetMapping("/getProduct")
    public RespBean getProduct(@RequestParam String word){
        MetaBean meta = new MetaBean(200,"获取成功");
        return new RespBean (searchService.getProduct(word), meta);
    }

    @GetMapping("/getDataBySort")
    public RespBean getDataBySort(@RequestParam String sortName){
        MetaBean meta = new MetaBean(200,"获取成功");
        return new RespBean (searchService.getDataBySort(sortName), meta);
    }
}
